| Conditions | 1 |
| Paths | 4096 |
| Total Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /*! |
||
| 30 | }( function( $ ) { |
||
| 31 | |||
| 32 | return $.effects.define( "bounce", function( options, done ) { |
||
| 33 | var upAnim, downAnim, refValue, |
||
| 34 | element = $( this ), |
||
| 35 | |||
| 36 | // Defaults: |
||
| 37 | mode = options.mode, |
||
| 38 | hide = mode === "hide", |
||
| 39 | show = mode === "show", |
||
| 40 | direction = options.direction || "up", |
||
| 41 | distance = options.distance, |
||
| 42 | times = options.times || 5, |
||
| 43 | |||
| 44 | // Number of internal animations |
||
| 45 | anims = times * 2 + ( show || hide ? 1 : 0 ), |
||
| 46 | speed = options.duration / anims, |
||
| 47 | easing = options.easing, |
||
| 48 | |||
| 49 | // Utility: |
||
| 50 | ref = ( direction === "up" || direction === "down" ) ? "top" : "left", |
||
| 51 | motion = ( direction === "up" || direction === "left" ), |
||
| 52 | i = 0, |
||
| 53 | |||
| 54 | queuelen = element.queue().length; |
||
| 55 | |||
| 56 | $.effects.createPlaceholder( element ); |
||
| 57 | |||
| 58 | refValue = element.css( ref ); |
||
| 59 | |||
| 60 | // Default distance for the BIGGEST bounce is the outer Distance / 3 |
||
| 61 | if ( !distance ) { |
||
| 62 | distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3; |
||
| 63 | } |
||
| 64 | |||
| 65 | if ( show ) { |
||
| 66 | downAnim = { opacity: 1 }; |
||
| 67 | downAnim[ ref ] = refValue; |
||
| 68 | |||
| 69 | // If we are showing, force opacity 0 and set the initial position |
||
| 70 | // then do the "first" animation |
||
| 71 | element |
||
| 72 | .css( "opacity", 0 ) |
||
| 73 | .css( ref, motion ? -distance * 2 : distance * 2 ) |
||
| 74 | .animate( downAnim, speed, easing ); |
||
| 75 | } |
||
| 76 | |||
| 77 | // Start at the smallest distance if we are hiding |
||
| 78 | if ( hide ) { |
||
| 79 | distance = distance / Math.pow( 2, times - 1 ); |
||
| 80 | } |
||
| 81 | |||
| 82 | downAnim = {}; |
||
| 83 | downAnim[ ref ] = refValue; |
||
| 84 | |||
| 85 | // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here |
||
| 86 | for ( ; i < times; i++ ) { |
||
| 87 | upAnim = {}; |
||
| 88 | upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
||
| 89 | |||
| 90 | element |
||
| 91 | .animate( upAnim, speed, easing ) |
||
| 92 | .animate( downAnim, speed, easing ); |
||
| 93 | |||
| 94 | distance = hide ? distance * 2 : distance / 2; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Last Bounce when Hiding |
||
| 98 | if ( hide ) { |
||
| 99 | upAnim = { opacity: 0 }; |
||
| 100 | upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
||
| 101 | |||
| 102 | element.animate( upAnim, speed, easing ); |
||
| 103 | } |
||
| 104 | |||
| 105 | element.queue( done ); |
||
| 106 | |||
| 107 | $.effects.unshift( element, queuelen, anims + 1 ); |
||
| 108 | } ); |
||
| 109 | |||
| 110 | } ) ); |
||
| 111 |